package xcu.lxj.nettychat.chat.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import xcu.lxj.nettychat.chat.domain.entity.Room;
import xcu.lxj.nettychat.chat.mapper.RoomMapper;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author XinJian Lei
 * @Date 2024/9/28 20:34
 * @Version 1.0
 */
@Service
public class RoomDao extends ServiceImpl<RoomMapper, Room> {
    public void refreshActiveTime(Long roomId, Long msgId, Date msgTime) {
        lambdaUpdate()
                .eq(Room::getId, roomId)
                .set(Room::getLastMsgId, msgId)
                .set(Room::getActiveTime, msgTime)
                .update();
    }

    public Map<Long, Room> getBatch(List<Long> roomIds) {
        Map<Long, Room> collect = lambdaQuery()
                .in(Room::getId, roomIds)
                .list().stream().collect(Collectors.toMap(Room::getId, room -> room));

        return collect;
    }
}
